package com.gitee.melin.bee.model;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 *
 * @author admin@gmail.com
 */
@MappedSuperclass
@Data
@FilterDef(name = "tenant_filter", parameters = @ParamDef(name = "currentTenant", type = "long"))
@Filter(name = "tenant_filter", condition = "tenant_id = :currentTenant")
public class TenantBaseEntity implements IEntity, Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long id;

	@Column(name = "tenant_id")
	private Long tenantId;

	@Column(name="CREATER", updatable=false)
	private String creater;
	@Column(name="MODIFIER")
	private String modifier;

	@JsonSerialize(using = LocalDateTimeSerializer.class)
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @Column(name="GMT_CREATED", updatable = false)
	private LocalDateTime gmtCreated;

	@JsonSerialize(using = LocalDateTimeSerializer.class)
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@Column(name="GMT_MODIFIED")
	private LocalDateTime gmtModified;

	public Long getId() {
		return id;
	}
}
